﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

namespace UI
{
    public class RecycleSelectHeroItem : RecycleSelectItemBase , IComparable 
    {
        public CommonIcon icon;
        public UILabel nameLabel;
        public UILabel levelLabel;

        UIHero uiHero;

        protected override void SetData(object value)
        {
            UIHero hero = value as UIHero;
            uiHero = hero;
            icon.SetData(hero.heroId, false);
            if (hero.talentLevel > 0)
            {
                nameLabel.text = hero.heroName + "+" + hero.talentLevel.ToString();
            }
            else
            {
                nameLabel.text = hero.heroName;
            }
            levelLabel.text = TableTextBlo.GetText("level") + hero.level;
        }

        public override string GetItemGUID()
        {
            return uiHero.guid; 
        }

        public UIHero GetUIHero()
        {
            return uiHero;
        }


        public int CompareTo(object obj)
        {
            RecycleSelectHeroItem itemX = this; 
            RecycleSelectHeroItem itemY = obj as RecycleSelectHeroItem;
            UIHero uiHeroX = itemX.GetUIHero();
            UIHero uiHeroY = itemY.GetUIHero();

            if (uiHeroX.heroData.quality > uiHeroY.heroData.quality)
            {
                return 1;
            }
            else if (uiHeroX.heroData.quality < uiHeroY.heroData.quality)
            {
                return -1;
            }
            else
            {
                if (uiHeroX.talentLevel > uiHeroY.talentLevel)
                {
                    return 1;
                }
                else if (uiHeroX.talentLevel < uiHeroY.talentLevel)
                {
                    return -1;
                }
                else
                {
                    if (uiHeroX.level > uiHeroY.level)
                    {
                        return 1;
                    }
                    else if (uiHeroX.level < uiHeroY.level)
                    {
                        return -1;
                    }
                    else
                    {
                        return uiHeroX.heroId.CompareTo(uiHeroY.heroId);
                    }
                }

            }
        }

    }

}